
import modal from "@/_js/modal";

import weexHttp from "@/_js/https"; ;
const weexFunction = weex.requireModule("WeexFunction");

var I18N = {};
I18N.en = {
  "终止成功":"Successful termination",
};
I18N.ja = {
  "终止成功":"终止成功",
};

I18N.ko = {
  "终止成功":"终止成功",
};

var language = weex.config.language;
// var language = "en";
var msg = I18N[language];
if(!msg){
  msg = {};
}
var T = function(text){
    return msg[text] || text;
};
export default {

  /******************************************* 辅助方法*/
  /** 校验参数
   * 
   * @param {参数} param 
   * @param {参数关键字数组} keys 
   * @param {turn弹出Load} hud
   */
   checkParam(param, keys, hud){
    hud&&modal.showLoad();
    for (let index = 0; index < keys.length; index++) {
      var key = keys[index];
      if (param[key] == null) {
        hud&&modal.hideLoad();
        modal.toast('缺失：'+key);
        return true;
      }
    }
    return false;
  },

  /******************************************* http*/
  /** HTTP 终止
   * @param {执行id} executeId 
   * 
   * @param {成功回调} success 
   * @param {失败回调} failure 
   */
  httpEnd(param, success=()=>{}, failure=()=>{}){

    var keys = ['executeId'];
    if (this.checkParam(param, keys, true)) return;

    weexHttp.postX('foundation/fundEnd',param,true,(data)=>{
      modal.hideLoad();
      if(data.status == 200){
        
        modal.toast(T('终止成功'));
        success&&success();
      } else {
        modal.toast(data.msg);
        failure&&failure();
      }
    });
  },
}